/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\quadrilateral.h"

BOOST_AUTO_TEST_SUITE( quadrilateral2d )


BOOST_AUTO_TEST_CASE( quadrilateral2d__default_constructor )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );
	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );
	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );
	BOOST_CHECK( a.p4()[0] == 0 );
	BOOST_CHECK( a.p4()[1] == 0 );

	sgl::quadrilateral<2> b(
		sgl::point<2>(1, 2),
		sgl::point<2>(3, 4),
		sgl::point<2>(5, 6),
		sgl::point<2>(7, 8));
	
	BOOST_CHECK( b.p1()[0] == 1 );
	BOOST_CHECK( b.p1()[1] == 2 );
	BOOST_CHECK( b.p2()[0] == 3 );
	BOOST_CHECK( b.p2()[1] == 4 );
	BOOST_CHECK( b.p3()[0] == 5 );
	BOOST_CHECK( b.p3()[1] == 6 );
	BOOST_CHECK( b.p4()[0] == 7 );
	BOOST_CHECK( b.p4()[1] == 8 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__copy_constructor )
{
	sgl::quadrilateral<2> a(
		sgl::quadrilateral<2>(
			sgl::point<2>(1, 2),
			sgl::point<2>(3, 4),
			sgl::point<2>(5, 6),
			sgl::point<2>(7, 8)));

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p2()[0] == 3 );
	BOOST_CHECK( a.p2()[1] == 4 );
	BOOST_CHECK( a.p3()[0] == 5 );
	BOOST_CHECK( a.p3()[1] == 6 );
	BOOST_CHECK( a.p4()[0] == 7 );
	BOOST_CHECK( a.p4()[1] == 8 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__copy_assignment )
{
	sgl::quadrilateral<2> a;
	a = sgl::quadrilateral<2>(
			sgl::point<2>(1, 2),
			sgl::point<2>(3, 4),
			sgl::point<2>(5, 6),
			sgl::point<2>(7, 8));

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p2()[0] == 3 );
	BOOST_CHECK( a.p2()[1] == 4 );
	BOOST_CHECK( a.p3()[0] == 5 );
	BOOST_CHECK( a.p3()[1] == 6 );
	BOOST_CHECK( a.p4()[0] == 7 );
	BOOST_CHECK( a.p4()[1] == 8 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__swap )
{
	sgl::quadrilateral<2> a(sgl::quadrilateral<2>(
		sgl::point<2>(1, 2),
		sgl::point<2>(3, 4),
		sgl::point<2>(5, 6),
		sgl::point<2>(7, 8)));
	sgl::quadrilateral<2> b;

	a.swap(b);

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );
	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );
	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );
	BOOST_CHECK( a.p4()[0] == 0 );
	BOOST_CHECK( a.p4()[1] == 0 );
	BOOST_CHECK( b.p1()[0] == 1 );
	BOOST_CHECK( b.p1()[1] == 2 );
	BOOST_CHECK( b.p2()[0] == 3 );
	BOOST_CHECK( b.p2()[1] == 4 );
	BOOST_CHECK( b.p3()[0] == 5 );
	BOOST_CHECK( b.p3()[1] == 6 );
	BOOST_CHECK( b.p4()[0] == 7 );
	BOOST_CHECK( b.p4()[1] == 8 );

	b.swap(a);

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p2()[0] == 3 );
	BOOST_CHECK( a.p2()[1] == 4 );
	BOOST_CHECK( a.p3()[0] == 5 );
	BOOST_CHECK( a.p3()[1] == 6 );
	BOOST_CHECK( a.p4()[0] == 7 );
	BOOST_CHECK( a.p4()[1] == 8 );
	BOOST_CHECK( b.p1()[0] == 0 );
	BOOST_CHECK( b.p1()[1] == 0 );
	BOOST_CHECK( b.p2()[0] == 0 );
	BOOST_CHECK( b.p2()[1] == 0 );
	BOOST_CHECK( b.p3()[0] == 0 );
	BOOST_CHECK( b.p3()[1] == 0 );
	BOOST_CHECK( b.p4()[0] == 0 );
	BOOST_CHECK( b.p4()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__p1 )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );

	a.p1()[0] = 1;
	a.p1()[1] = 1;

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__p2 )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );

	a.p2()[0] = 1;
	a.p2()[1] = 1;

	BOOST_CHECK( a.p2()[0] == 1 );
	BOOST_CHECK( a.p2()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__p3 )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );

	a.p3()[0] = 1;
	a.p3()[1] = 1;

	BOOST_CHECK( a.p3()[0] == 1 );
	BOOST_CHECK( a.p3()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__p4 )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.p4()[0] == 0 );
	BOOST_CHECK( a.p4()[1] == 0 );

	a.p4()[0] = 1;
	a.p4()[1] = 1;

	BOOST_CHECK( a.p4()[0] == 1 );
	BOOST_CHECK( a.p4()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__geometric_type )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::quadrilateral );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__dimensions )
{
	sgl::quadrilateral<2> a;

	BOOST_CHECK( a.dimensions() == 2 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__operator_equality )
{
	sgl::quadrilateral<2> a;
	sgl::quadrilateral<2> b;

	BOOST_CHECK( a == b );

	sgl::quadrilateral<2> c(sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
		sgl::point<2>(5, 6), sgl::point<2>(5, 6));
	sgl::quadrilateral<2> d(sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
		sgl::point<2>(5, 6), sgl::point<2>(5, 6));

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__operator_inequality )
{
	sgl::quadrilateral<2> a;
	sgl::quadrilateral<2> b(sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
		sgl::point<2>(5, 6), sgl::point<2>(5, 6));

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__addition )
{
	sgl::quadrilateral<2> a;
	a += sgl::vector<2>(1, 2);

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p2()[0] == 1 );
	BOOST_CHECK( a.p2()[1] == 2 );
	BOOST_CHECK( a.p3()[0] == 1 );
	BOOST_CHECK( a.p3()[1] == 2 );
	BOOST_CHECK( a.p4()[0] == 1 );
	BOOST_CHECK( a.p4()[1] == 2 );

	sgl::quadrilateral<2> b;
	sgl::vector<2> c(1, 2);
	sgl::quadrilateral<2> d = b+c;

	BOOST_CHECK( d.p1()[0] == 1 );
	BOOST_CHECK( d.p1()[1] == 2 );
	BOOST_CHECK( d.p2()[0] == 1 );
	BOOST_CHECK( d.p2()[1] == 2 );
	BOOST_CHECK( d.p3()[0] == 1 );
	BOOST_CHECK( d.p3()[1] == 2 );
	BOOST_CHECK( d.p4()[0] == 1 );
	BOOST_CHECK( d.p4()[1] == 2 );

	sgl::quadrilateral<2> e = c+b;

	BOOST_CHECK( e.p1()[0] == 1 );
	BOOST_CHECK( e.p1()[1] == 2 );
	BOOST_CHECK( e.p2()[0] == 1 );
	BOOST_CHECK( e.p2()[1] == 2 );
	BOOST_CHECK( e.p3()[0] == 1 );
	BOOST_CHECK( e.p3()[1] == 2 );
	BOOST_CHECK( e.p4()[0] == 1 );
	BOOST_CHECK( e.p4()[1] == 2 );
}

BOOST_AUTO_TEST_CASE( quadrilateral3d__subtraction )
{
	sgl::quadrilateral<2> a;
	a -= sgl::vector<2>(1, 2);

	BOOST_CHECK( a.p1()[0] == -1 );
	BOOST_CHECK( a.p1()[1] == -2 );
	BOOST_CHECK( a.p2()[0] == -1 );
	BOOST_CHECK( a.p2()[1] == -2 );
	BOOST_CHECK( a.p3()[0] == -1 );
	BOOST_CHECK( a.p3()[1] == -2 );
	BOOST_CHECK( a.p4()[0] == -1 );
	BOOST_CHECK( a.p4()[1] == -2 );

	sgl::quadrilateral<2> b;
	sgl::vector<2> c(1, 2);
	sgl::quadrilateral<2> d = b-c;

	BOOST_CHECK( d.p1()[0] == -1 );
	BOOST_CHECK( d.p1()[1] == -2 );
	BOOST_CHECK( d.p2()[0] == -1 );
	BOOST_CHECK( d.p2()[1] == -2 );
	BOOST_CHECK( d.p3()[0] == -1 );
	BOOST_CHECK( d.p3()[1] == -2 );
	BOOST_CHECK( d.p4()[0] == -1 );
	BOOST_CHECK( d.p4()[1] == -2 );
}

BOOST_AUTO_TEST_SUITE_END()

